<?php
include dirname(dirname(dirname(__FILE__))).'/include/user-verify.php';
include dirname(dirname(__FILE__)).'/user-manage/functions.php';
include_once dirname(dirname(dirname(__FILE__))).'/include/host-base.php';
include dirname(__FILE__).'/functions.php';


$user_map = getCurDutyUser();
$user_map['']='';
?>

<!DOCTYPE html>
<html>
	<head>
		<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php'; ?>
		<script type="text/javascript">
			$(document).ready(function() {
				<?php
					$duty_table_info = "";
					$duty_table = array();
					$cur_id = 0;
					if(isset($_GET['time-id'])) {
						$cur_id = $_GET['time-id'];
					} else {
						$cur_id = getCurDutyTableId();
					}
					$cur_id = addslashes($cur_id);
					$duty_table_info = getDutyTableById($cur_id);
					$duty_table = json_decode($duty_table_info['table_content'],true);
					echo '$("#time-id option[value=\''.$cur_id.'\']").attr("selected","selected");';
				?>
				$("#time-id").change(function() {
					$("#submit-form").submit();
				});
			});
		</script>

		<link rel="stylesheet" type="text/css" href="../css/style.css">
	</head>
	<body>
		<div class="col-md-12">
			<div>
				<h3> 值班表查询 </h3>
			</div>
			<div>
				<form id="submit-form" class="form-inline" role="form" method="GET" 
					style="margin-bottom:20px;" action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>>
				选择查询值班时间<select class="form-control" style="margin-left:10px;" name="time-id" id="time-id">
				  <?php 
				  	$list = getStartEndTimeList();
				  	foreach($list as $key=>$value) {
				  		echo '<option value="'.$key.'">'.$value.'</option>';
				  	}
				  ?>
				</select>
				</form>
				<table class="table table-striped table-bordered table-hover table-condensed " id="default-table">
				  <tr>
				  	<th>#</th>
				  	<th>星期一</th>
				  	<th>星期二</th>
				  	<th>星期三</th>
				  	<th>星期四</th>
				  	<th>星期五</th>
				  	<th>星期六</th>
				  	<th>星期天</th>
				  </tr>
				  <tr>
				  	<td>7:30~10:00</td>
				  	<?php 
				  		for($i=1;$i<=7;$i++) {
				  			echo '<td>';
				  			if(isset($user_map[$duty_table[$i]['a']])) {
				  				echo $user_map[$duty_table[$i]['a']];
				  			}
				  			echo '</td>';
				  		}
				  	?>
				  </tr>
				  <tr>
				  	<td>10:00~12:30</td>
				  	<?php 
				  		for($i=1;$i<=7;$i++) {
				  			echo '<td>';
				  			if(isset($user_map[$duty_table[$i]['b']])) {
				  				echo $user_map[$duty_table[$i]['b']];
				  			}
				  			echo '</td>';
				  		}
				  	?>
				  </tr>
				  <tr>
				  	<td>12:30~14:30</td>
				  	<?php 
				  		for($i=1;$i<=7;$i++) {
				  			echo '<td>';
				  			if(isset($user_map[$duty_table[$i]['c']])) {
				  				echo $user_map[$duty_table[$i]['c']];
				  			}
				  			echo '</td>';
				  		}
				  	?>
				  </tr>
				  <tr>
				  	<td>14:30~16:00</td>
				  	<?php 
				  		for($i=1;$i<=7;$i++) {
				  			echo '<td>';
				  			if(isset($user_map[$duty_table[$i]['d']])) {
				  				echo $user_map[$duty_table[$i]['d']];
				  			}
				  			echo '</td>';
				  		}
				  		echo '</td>';
				  	?>
				  </tr>
				  <tr>
				  	<td>16:00~18:30</td>
				  	<?php 
				  		for($i=1;$i<=7;$i++) {
				  			echo '<td>';
				  			if(isset($user_map[$duty_table[$i]['e']])) {
				  				echo $user_map[$duty_table[$i]['e']];
				  			}
				  			echo '</td>';
				  		}
				  	?>
				  </tr>
				  <tr>
				  	<td>18:30~22:30</td>
				  	<?php 
				  		for($i=1;$i<=7;$i++) {
				  			echo '<td>';
				  			if(isset($user_map[$duty_table[$i]['f']])) {
				  				echo $user_map[$duty_table[$i]['f']];
				  			}
				  			echo '</td>';
				  		}
				  	?>
				  </tr>
				</table>
				<h5>最近一次修改于 <b><?php echo $duty_table_info['update_time'];?></b></h5>
			</div>
		</div>
	</body>
</html>